local zhangguoji = fk.CreateSkill{
  name = "lzsj__zhangguoji",
}


Fk:loadTranslationTable{
  ["lzsj__zhangguoji"] = "掌国计",
  ["@zhangguoji-turn"] = "掌国计",
  ["#zhanguoji-show"] = "请选择一种花色的牌展示",
  ["#lzsj__zhangguoji"] = "掌国计：请选择弃置的牌",
  [":lzsj__zhangguoji"] = "出牌阶段开始时，你可展示手牌中一种花色的所有牌并摸等量牌，若如此做，弃牌阶段开始时，你须弃置X张此花色的手牌（X为你超出手牌上限的手牌数，不足则全弃）",

  ["$lzsj__zhangguoji1"] = "鞍钢高炉昼夜转，铸的就是新国梁！",
  ["$lzsj__zhangguoji2"] = "五年计划草案？得先浇透我这杯高粱酒！",
}

local U = require "packages/utility/utility"

zhangguoji:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhangguoji.name) and player.phase == Player.Play
    and not player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to_show = {}
    local listNames = {"log_spade", "log_club", "log_heart", "log_diamond"}
    local listCards = { {}, {}, {}, {} }
    local can_show
    for _, id in ipairs(player:getCardIds("h")) do
      local suit = Fk:getCardById(id).suit
      if suit ~= Card.NoSuit then
        table.insertIfNeed(listCards[suit], id)
        can_show = true
      end
    end
    if can_show then
      local choice = U.askForChooseCardList(room, player, listNames, listCards, 1, 1, zhangguoji.name, "#zhanguoji-show", false, false)
      if #choice == 1 then
        to_show = table.filter(player:getCardIds("h"), function(id)
          return Fk:getCardById(id):getSuitString(true) == choice[1]
        end)
      end
      if #to_show > 0 then
        player:showCards(to_show)
        player:drawCards(#to_show, zhangguoji.name)
        if not player.dead then
          room:setPlayerMark(player, "@zhangguoji-turn", {choice[1]})
        end
      end
    end
  end,
})

zhangguoji:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhangguoji.name) and player.phase == Player.Discard
    and not player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suit = player:getTableMark("@zhangguoji-turn")[1]
    local n = #table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getSuitString() == U.ConvertSuit(suit, "sym", "str") end)
    n = math.min(n, player:getHandcardNum() - player:getMaxCards())
    if n > 0 then
      room:askToDiscard(player, {
        min_num = n,
        max_num = n,
        include_equip = false,
        skill_name = zhangguoji.name,
        cancelable = false,
        prompt = "#lzsj__zhangguoji",
        pattern = ".|.|"..U.ConvertSuit(suit, "sym", "str"),
      })
    end
  end,
})

return zhangguoji